package easy;

public class Solution_1945 {

    public int getLucky(String s, int k) {
        StringBuffer buffer = new StringBuffer();
        for (int i = 0; i < s.length(); i++) {
            buffer.append(s.charAt(i) - 'a' + 1);
        }
        int num = 0;
        for (int j = 0; j < buffer.length(); j++) {
            num += (buffer.charAt(j) - '0');
        }
        for (int i = 1; i < k; i++) {
            int val = 0;
            while (num > 0) {
                val += (num % 10);
                num /= 10;
            }
            num = val;
        }
        return num;
    }

    public static void main(String[] args) {
        Solution_1945 model = new Solution_1945();
        System.out.println(model.getLucky("iiii", 1));
        System.out.println(model.getLucky("leetcode", 2));
    }
}
